/*************************************************************
     copyright (c) Southwest JiaoTong University 
	                    School of Information and Scientific Technology
     filename: linklist.cpp
	 description: the implementation of some important link list algorithm
	 current version: 1.0
	 author: Bryan.Li
	 date: 2012.8.5
**************************************************************/
#include "linklist.h"


template<class T>
void Stack<T>::Push(const T & item)
{
	StackNode<T>  *p=new StackNode<T>(item,top);   // construc a new node;
	if (!p)
	{
		cerr<<"out of memory\n";
		exit(-1);
	}
	p->next=top;
	top=p;
}

template<class T>
T Stack<T>::pop()
{
	if (isEmpty())
	{
		return 0;
	}
	StackNode<T> *p=top;
	top=top->next;
	T t=top->data;
	delete p;
	return t;

}

template<class T>
T Stack<T>::GetTop()
{
	if (isEmpty())
    {
		exit(-1);
    }
	T t=top->data;
	return t;
}

template<class T>
void Stack<T>::makeEmpty()
{
	StackNode<T> *P=top;
    while(top!=NULL)
	{
		P=top;
		top=top->next;
		delete P;
	}
};

template<class T>
void Stack<T>::printStack()
{
	
	StackNode<T> *p=top;
	while(p!=NULL)
	{
		std::cout<<p->data<<"  ";
		p=p->next;
	}
	cout<<"\n";
}